package com.zhuiyun.project.api.apppatient.service.Impl;

import com.zhuiyun.project.api.apppatient.entity.Patient;
import com.zhuiyun.project.api.apppatient.mapper.PatientMapper;
import com.zhuiyun.project.api.apppatient.model.PatientModel;
import com.zhuiyun.project.api.apppatient.service.PatientService;

import com.zhuiyun.project.common.response.CommonResult;
import com.zhuiyun.project.util.BeanUtils;
import com.zhuiyun.project.util.ObjectUtils;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @ClassName PatientServiceImpl
 * @Description TODO
 * @Author Root
 * @Date 2023/7/3 9:54
 **/
@Service
public class PatientServiceImpl implements PatientService {
    @Autowired
    PatientMapper patientMapper;

    /**
    * @Author Root
    * @Description 录入病例
    * @Date 2023/7/3 14:33
    * @Return com.zhuiyun.project.common.response.CommonResult
    * @param patientModel
    */
    @Override
    public CommonResult insertPatient(PatientModel patientModel) {
        Patient patient = new Patient();
        // patientModel 对象拷贝成 patientModel
        BeanUtils.copy(patientModel, patient);
        patient.setCreateTime(new Date());
        patient.setUpdateTime(new Date());
        int i = patientMapper.insertSelective(patient);
        return CommonResult.ok(i);
    }
    /**
    * @Author Root
    * @Description 通过名字查询
    * @Date 2023/7/3 16:53
    * @Return com.zhuiyun.project.common.response.CommonResult
    * @param
    */
    @Override
    public CommonResult getPatientByName(Integer userId,String cycle,String disease) {
        //判断名字是否为空
        if (ObjectUtils.isNotEmpty(userId)) {
            List<Patient> patientByName = patientMapper.getPatientByName(userId,cycle,disease);
            return CommonResult.ok(patientByName);
        } else {
            return CommonResult.error();
        }
    }
    /**
    * @Author Root
    * @Description 修改用户名称
    * @Date 2023/7/11 19:28
    * @Return com.zhuiyun.project.common.response.CommonResult
    * @param
    * @param
    */
    @Override
    public CommonResult getPatientByCycle1(Integer userId) {
        if (ObjectUtils.isNotEmpty(userId)) {
            List<Patient> PatientByCycle1 = patientMapper.getPatientByCycle1(userId);
            return CommonResult.ok(PatientByCycle1);
        } else {
            return CommonResult.error();
        }
    }
    /**
     * @Author Root
     * @Description 通过名字查询获取周期
     * @Date 2023/7/24 17:21
     * @Return com.zhuiyun.project.common.response.CommonResult
     * @param
     */
    public CommonResult getPatientByCycle2(Integer userId) {
        if (ObjectUtils.isNotEmpty(userId)) {
            List<Patient> PatientByCycle2 = patientMapper.getPatientByCycle2(userId);
            return CommonResult.ok(PatientByCycle2);
        } else {
            return CommonResult.error();
        }
    }
    /**
     * @Author Root
     * @Description 通过名字查询获取周期
     * @Date 2023/7/24 17:21
     * @Return com.zhuiyun.project.common.response.CommonResult
     * @param
     */
    public CommonResult getPatientByCycle3(Integer userId) {
        if (ObjectUtils.isNotEmpty(userId)) {
            List<Patient> PatientByCycle3 = patientMapper.getPatientByCycle3(userId);
            return CommonResult.ok(PatientByCycle3);
        } else {
            return CommonResult.error();
        }
    }
    /**
     * @Author Root
     * @Description 通过名字查询获取周期
     * @Date 2023/7/24 17:21
     * @Return com.zhuiyun.project.common.response.CommonResult
     * @param
     */
    public CommonResult getPatientByCycle4(Integer userId) {
        //如果名字不为空
        if (ObjectUtils.isNotEmpty(userId)) {
            List<Patient> PatientByCycle4 = patientMapper.getPatientByCycle4(userId);
            return CommonResult.ok(PatientByCycle4);
        } else {
            return CommonResult.error();
        }
    }
    /**
    * @Author Root
    * @Description 修改患者姓名
    * @Date 2023/7/25 9:25
    * @Return com.zhuiyun.project.common.response.CommonResult
    * @param name
    * @param newName
    */
    public CommonResult updatePatientByName(String name, String newName) {
        Integer i = patientMapper.updatePatientByName(name, newName);
        if (i > 0) {
            return CommonResult.ok(i);
        } else {
            return CommonResult.error();
        }
    }
    /**
     * @Author Root
     * @Description 修改状态
     * @Date 2023/7/11 19:24
     * @Return com.zhuiyun.project.common.response.CommonResult
     * @param patient
     */
    @Override
    public CommonResult updatePatientById(Patient patient) {
        Integer i = patientMapper.updatePatientById(patient);
        if (i > 0) {
            return CommonResult.ok(i);
        } else {
            return CommonResult.error();
        }
    }
}
